package com.magicode.cms.dao.impl;

import java.util.List;
import java.util.Map;

import javax.transaction.Transactional;

import org.springframework.stereotype.Repository;

import com.magicode.cms.dao.IVideoPlayHistoryDao;
import com.magicode.cms.entiy.base.News;
import com.magicode.cms.entiy.base.NewsCollect;
import com.magicode.cms.entiy.base.Video;
import com.magicode.cms.entiy.base.VideoPlayHistory;
import com.magicode.common.dao.PageResults;
@Transactional
@Repository("daoVideoPlayHistory")
public class VideoPlayHistoryDaoImpl extends BaseDaoImpl<VideoPlayHistory> implements IVideoPlayHistoryDao {

	@Override
	public PageResults VideoPlayHistorylist(Map<String, String> prams,
			Integer pageNo, Integer pageSize) {
		String hql = "select n from "+VideoPlayHistory.class.getName()+" t , "+News.class.getName()+" n  left outer join fetch n.mainPic " +
				"  where t.video = n and  t.user.id = '"+prams.get("userid")+"'" ;
		
		String counthql= "select count(t.id) from "+VideoPlayHistory.class.getName()+" t  "  +
				"  where  t.user.id = '"+prams.get("userid")+"'" ;
		PageResults pageResults = commonDaoService.findPageByFetchedHql(hql, counthql, pageNo==null?1:pageNo, pageSize, new String[]{});
		return pageResults;
	}

	@Override
	public void deleteVideoPlayHistorylist(String userid) {
		// TODO Auto-generated method stub
		String hql = " from "+VideoPlayHistory.class.getName()+" t " +
				"  where  t.user.id = '"+userid+"'" ;
		List<VideoPlayHistory> vphs = commonDaoService.getListByHQL(hql);
		commonDaoService.deleteAll(vphs);
	}

}
